<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //获得当前登录用户
            var userStr = sessionStorage.getItem("user")
            var user = JSON.parse(userStr)
            var totalPage = 1;
            //定义一个临时当前页
            var currentPage = 1;
            var dataList = [];//临时定义一个dataList为一个空数组



            //获取第一个
            $.get("/users/" + user.id + "/travel", {currentPage: currentPage, pageSize: 5}, function (data) {
                //合并数组,返回第一个数据,如[1,2]和[3]编程[1,2,3]
                $.merge(dataList, data.list)
                //利用render渲染数据到页面
                //因为渲染是要一个对象
                $(".travels").renderValues({list: dataList},{
                    //setHref表示遍历元素时,如果发现render-fun="setHref"这个属性,会解析并调用这个setHref函数
                    //传入参数就是render-key属性指定的值
                    //item,要操作的标签,就是拥有render-fun="setHref"属性的标签
                    //value,render-key属性指定的值
                    setHref:function (item,value) {
                        //把href取出来
                        var href=$(item).attr("href");
                        //然后拼接href
                        href=href+value;
                        //重新设置回去
                        $(item).prop("href",href);
                    }
                })
                currentPage += 1;
                totalPage = data.pages;
            })
            //屏幕滚动事件
            $(window).scroll(function () {
                console.log($(window).height() +"+"+ $(window).scrollTop() +">="+ $(document).height());
                if ($(window).height() + $(window).scrollTop() >= $(document).height()) {
                    if (currentPage <= totalPage) {
                        $.get("/users/" + user.id + "/travel", {
                            currentPage: currentPage,
                            pageSize: 5
                        }, function (data) {
                            //合并数组,返回第一个数据,如[1,2]和[3]编程[1,2,3]
                            $.merge(dataList, data.list)
                            //数据渲染
                            $(".travels").renderValues({list: dataList},{
                                setHref:function (item,value) {
                                    //把href取出来
                                    var href=$(item).attr("href");
                                    //然后拼接href
                                    href=href+value;
                                    //重新设置回去
                                    $(item).prop("href",href);
                                }
                            })
                            currentPage += 1;
                        })
                    }else{
                            $(document).dialog({
                                type : 'toast',
                                content: '<span class="info-text">到底了</span>',
                                autoClose: 2500
                            });
                    }
                }
            })
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<!--在这里选择回显render-->
<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a href="/mine/editTravels.html?id=" render-fun="setHref" render-key="list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
